<?php
/**
 * Created by PhpStorm.
 * User: andrei
 * Date: Jun 27, 2012
 * Time: 3:58:15 PM
 * To change this template use File | Settings | File Templates.
 */
 
class Db_Products_MemoryListProductPages extends Common {
	protected static $tableName = TAB_MEMORY_LIST_PRODUCT_PAGES;
	protected static $dbFields = array(
        'id',
		'mpp_memory_product_id',
		'mpp_template_id',
		'mpp_page_index',
        'deleted'
	);


	/**
	 * @var Db_Products_MemoryListProductPages
	 */
	public $objectArray;

	public $id;
	public $mpp_memory_product_id;
	public $mpp_template_id;
	public $mpp_page_index;
    public $deleted;

    function __construct($value=NULL, $fieldName=NULL) {
        parent::__construct($value, $fieldName);
    }

	public static function getMemoryProductsUsedByTemplateId($templateId) {
		if(!$templateId) {
			return false;
		}
		$sql = "SELECT COUNT(*) FROM ?f WHERE `mpp_template_id` = ?d AND `deleted` = 0 GROUP BY `mpp_memory_product_id`";
		return self::$DB->selectCell($sql, self::$tableName, $templateId);
	}
}